package com.abel.bigwater.dataserver.model.qdies

import com.abel.bigwater.data.BcdString
import io.netty.buffer.Unpooled
import org.junit.Test

import org.junit.Assert.*
import org.slf4j.LoggerFactory

class MainUploadModeDataTest {

    @Test
    fun fillSet() {
        val buf = Unpooled.buffer()
        MainPacket().apply {
            address = BcdString(byteArrayOf(12, 0, 0, 1), true)
            func = FuncType.SetUploadMode
            data = MainSetUploadModeData()

            fill(buf)
        }

        val str = BcdString.create(buf, buf.readableBytes()).bcdString
        lgr.info(str)
        assertEquals("set upload-mode", DEMO_SET_UPLOAD_MODE, str)
    }

    @Test
    fun fillAsk() {
        val buf = Unpooled.buffer()
        MainPacket().apply {
            address = BcdString(byteArrayOf(12, 0, 0, 1), true)
            func = FuncType.AskUploadMode
            data = MainAskUploadModeData()

            fill(buf)
        }

        val str = BcdString.create(buf, buf.readableBytes()).bcdString
        lgr.info(str)
        assertEquals("ask upload-mode", DEMO_ASK_UPLOAD_MODE, str)
    }

    companion object {
        private val lgr = LoggerFactory.getLogger(MainUploadModeDataTest::class.java)

        const val DEMO_SET_UPLOAD_MODE = "68120000012701025b16"

        const val DEMO_ASK_UPLOAD_MODE = "681200000137004e16"
    }
}